package org.itboys.admin.service.lasted;

import org.itboys.admin.entity.lasted.SystemDictionary;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.mongodb.utils.page.Page;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseService;
import org.itboys.param.ParamUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作者：zzq
 * 日期：2017年3月6日
 * 描述：字典_Service_，zzq重新写的
 */
@Service
public class SystemDictionaryService extends BaseService<SystemDictionary,Long>  {
    @Resource(name = "adminDS")
    private MongoDataSource ds;

    @Override
    protected MongoDataSource getMongoDataSource() {
        return ds;
    }

    @Override
    protected Class<SystemDictionary> getEntityClass() {
        return SystemDictionary.class;
    }
    /**
     * 修改或新增
     * @param dictionary
     */
    public void saveDictionary(SystemDictionary dictionary){
        if(dictionary.getId()==0l){
            super.save(dictionary);
        }else{
            super.updateExceptEmpty(dictionary.getId(),dictionary);
        }
    }
     public Page<SystemDictionary> selectDictionary(HttpServletRequest request){
        Map<String,Object> param =new HashMap<String, Object>();
        param.put("isDeleted", 0);
        Map<String,String> containsparam = ParamUtil.packageMongoVagueParam(request,"key","value","name");
        org.itboys.mongodb.utils.page.Page<SystemDictionary> result=super.containpageQuery(containsparam,param,request);
        return result;

    }
    public List<SystemDictionary> getDictionaryByKey(String key){
       Map<String,Object> param=new HashMap<String,Object>();
       param.put("key",key);
        param.put("isDeleted", 0);
       return super.list(param);
    }
    public SystemDictionary getDictionaryByKey2(String key){
        Map<String,Object> param=new HashMap<String,Object>();
        param.put("key",key);
        param.put("isDeleted", 0);
        return super.list(param).get(0);
    }
    public List<SystemDictionary> getDictionaryByKeys(List<String> keys){
        Map<String,Object> param=new HashMap<String,Object>();
        param.put("isDeleted", 0);
        if(ListUtil.isNotNull(keys)){
            param.put("key in",keys);
        }
        return super.list(param);
    }



}
